<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>业务数据栏目管理</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
 		<link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
  		<link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
  		<style>
  			.layui-form-label{width: 90px;}
  			.layui-input-block{margin-left: 125px;}
  			.layui-upload-img{width: 92px;height: 92px;margin: 0 10px 10px 0;}
  		</style>
	</head>
	<body>
		<div class="layui-fluid">
			<div class="layui-card">
				<div class="layui-card-body" style="padding: 15px;">
					<form class="layui-form" action="" lay-filter="component-form-group" style="padding: 10px 0 0 0;">
						<div class="layui-form-item">
								<div  class="layui-inline">
									<label class="layui-form-label">栏目名称</label>
								    <div class="layui-input-block">
						              <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入栏目名称" class="layui-input">
						            </div>
								</div>
								<div  class="layui-inline">
									<label class="layui-form-label">是否有效</label>
								    <div class="layui-input-block">
								      <select name="city" lay-verify="required">
								        <option value=""></option>
								        <option value="0">失效</option>
								        <option value="1">有效</option>
								      </select>
								    </div>
								</div>
								<div  class="layui-inline">
									<button class="layui-btn">查询</button>
								</div>
					    </div>
					</form>
					<hr>
					<div class="layui-btn-group demoTable" style="margin-bottom: 5px;">
					  <button class="layui-btn layui-btn-primary " data-type="add"><i class="layui-icon">&#xe654;</i>新增</button>
					  <button class="layui-btn layui-btn-primary "><i class="layui-icon">&#x1006;</i>批量禁用</button>
					  <button class="layui-btn layui-btn-primary "><i class="layui-icon">&#xe605;</i>批量启用</button>
					  <!--<button class="layui-btn" data-type="getCheckData">获取选中行数据</button>
					  <button class="layui-btn" data-type="getCheckLength">获取选中数目</button>
					  <button class="layui-btn" data-type="isAll">验证是否全选</button>-->
					</div>
					<table class="layui-table" lay-data="{cellMinWidth: 80,height:472, url:'./data/data1.json', page:true, id:'idTest'}" lay-filter="demo">
					  <thead>
					    <tr>
					      <th lay-data="{type:'checkbox'}"></th>
					      <th lay-data="{field:'title', sort: true, width:280}">栏目名称</th>
					      <th lay-data="{field:'joggle'}">数据接口</th>
					      <th lay-data="{field:'flag', width:110, sort: true}">状态</th>
					      <th lay-data="{fixed: 'right', width:300, align:'center', toolbar: '#barDemo'}">操作</th>
					    </tr>
					  </thead>
					</table>
					<script type="text/html" id="barDemo">
					  <a class="layui-btn  layui-btn-normal layui-btn-xs" lay-event="detail"><i class="layui-icon">&#xe63c;</i>详情</a>
					  <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon">&#xe642;</i>编辑</a>
					  <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</a>
					</script>
					<div id="addModal" style="display: none;">
						<form class="layui-form" action="" lay-filter="component-form-group" style="margin: 10px;">
							<div class="layui-form-item">
								<label class="layui-form-label">栏目标题</label>
						        <div class="layui-input-block">
						            <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
						        </div>
					    	</div>
					    	<div class="layui-form-item" >
					    		<label class="layui-form-label">是否有效</label>
								<div class="layui-input-block">
								    <select name="city" lay-verify="required">
								        <option value=""></option>
								        <option value="0">失效</option>
								        <option value="1" selected="">有效</option>
								    </select>
								</div>
					    	</div>
					       <div class="layui-form-item" data-name="root">
					       		<label class="layui-form-label">数据接口</label>
						            <div class="layui-input-block">
						            <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入数据接口" class="layui-input">
						        </div>
					       </div>
					       
							<div class="layui-form-item">
							    <div class="layui-input-block">
							      <button class="layui-btn" lay-submit="" lay-filter="demo1">提交</button>
							      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
							    </div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
		<script src="../../layuiadmin/layui/layui.js"></script>  
		<script>
			layui.use(['form','table','upload'], function(){
			  var form = layui.form;
			  var table = layui.table;
			  var $ = layui.jquery
 			 ,upload = layui.upload;
			  upload.render({
				    elem: '#test2'
				    ,url: '/upload/'
				    ,multiple: true
				    ,before: function(obj){
				      //预读本地文件示例，不支持ie8
				      obj.preview(function(index, file, result){
				        $('#demo2').append('<img src="'+ result +'" alt="'+ file.name +'" class="layui-upload-img">')
				      });
				    }
				    ,done: function(res){
				      //上传完毕
				    }
				  });
			  
			   //监听表格复选框选择
			  table.on('checkbox(demo)', function(obj){
			    console.log(obj)
			  });
			  //监听工具条
			  table.on('tool(demo)', function(obj){
			    var data = obj.data;
			    if(obj.event === 'detail'){
			      layer.msg('ID：'+ data.id + ' 的查看操作');
			    } else if(obj.event === 'del'){
			      layer.confirm('真的删除行么', function(index){
			        obj.del();
			        layer.close(index);
			      });
			    } else if(obj.event === 'edit'){
			      layer.alert('编辑行：<br>'+ JSON.stringify(data))
			    }
			  });
			  
			  var $ = layui.$, active = {
			    getCheckData: function(){ //获取选中数据
			      var checkStatus = table.checkStatus('idTest')
			      ,data = checkStatus.data;
			      layer.alert(JSON.stringify(data));
			    }
			    ,getCheckLength: function(){ //获取选中数目
			      var checkStatus = table.checkStatus('idTest')
			      ,data = checkStatus.data;
			      layer.msg('选中了：'+ data.length + ' 个');
			    }
			    ,isAll: function(){ //验证是否全选
			      var checkStatus = table.checkStatus('idTest');
			      layer.msg(checkStatus.isAll ? '全选': '未全选')
			    }
			  };
			  
			  $('.demoTable .layui-btn').on('click', function(){
			    var type = $(this).data('type');
			    active[type] ? active[type].call(this) : '';
			  });
			  
			  form.on('select(grade)', function(data){
				   if(data.value=='0'){
				   		$('[data-name="root"]').removeClass('layui-hide')
				   }else{
				   		$('[data-name="root"]').addClass('layui-hide')
				   }
				});
			  
			  $('[data-type="add"]').on('click', function(){
				layer.open({
				  type: 1,
				  area: ['550px', '300px'],
				  fixed: false, //不固定
				  maxmin: true,
				  content: $('#addModal')
				});
			});
			});
		</script>
	</body>
</html>
